Added C bindings for host.supported_bootloaders.
authorEwan Mellor <ewan@xensource.com>
Wed, 21 Feb 2007 00:04:59 +0000 (00:04 +0000)
committerEwan Mellor <ewan@xensource.com>
Wed, 21 Feb 2007 00:04:59 +0000 (00:04 +0000)
Signed-off-by: Ewan Mellor <ewan@xensource.com>
tools/libxen/include/xen_host.h
tools/libxen/include/xen_string_set.h [new file with mode: 0644]
tools/libxen/src/xen_host.c
tools/libxen/src/xen_string_set.c [new file with mode: 0644]
tools/libxen/src/xen_string_set.h [new file with mode: 0644]
tools/libxen/test/test_bindings.c

index e98d7e5bf9835510b2b885f18ef9de68c0673b49..568973a4644cafd2655a8317124843fe1b6a3d61 100644 (file)
@@ -26,6 +26,7 @@
 #include "xen_pbd_decl.h"
 #include "xen_pif_decl.h"
 #include "xen_sr_decl.h"
+#include "xen_string_set.h"
 #include "xen_string_string_map.h"
 #include "xen_vm_decl.h"
 
@@ -73,6 +74,7 @@ typedef struct xen_host_record
     char *name_description;
     xen_string_string_map *software_version;
     xen_string_string_map *other_config;
+    struct xen_string_set *supported_bootloaders;
     struct xen_vm_record_opt_set *resident_vms;
     xen_string_string_map *logging;
     struct xen_pif_record_opt_set *pifs;
@@ -218,6 +220,13 @@ extern bool
 xen_host_get_other_config(xen_session *session, xen_string_string_map **result, xen_host host);
 
 
+/**
+ * Get the supported_bootloaders field of the given host.
+ */
+extern bool
+xen_host_get_supported_bootloaders(xen_session *session, struct xen_string_set **result, xen_host host);
+
+
 /**
  * Get the resident_VMs field of the given host.
  */
diff --git a/tools/libxen/include/xen_string_set.h b/tools/libxen/include/xen_string_set.h
new file mode 100644 (file)
index 0000000..a14af94
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2006-2007, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ */
+
+#ifndef XEN_STRING_SET_H
+#define XEN_STRING_SET_H
+
+
+#include "xen_common.h"
+
+
+typedef struct xen_string_set
+{
+    size_t size;
+    char *contents[];
+} xen_string_set;
+
+
+/**
+ * Allocate a xen_string_set of the given size.
+ */
+extern xen_string_set *
+xen_string_set_alloc(size_t size);
+
+/**
+ * Free the given xen_string_set.  The given set must have been allocated
+ * by this library.
+ */
+extern void
+xen_string_set_free(xen_string_set *set);
+
+
+#endif
index 591d6f4be120810b4e1b3c42518edd0a7db65700..24cc4140ccab861c6ca233e8cef693b8a47bcffa 100644 (file)
@@ -58,6 +58,9 @@ static const struct_member xen_host_record_struct_members[] =
         { .key = "other_config",
           .type = &abstract_type_string_string_map,
           .offset = offsetof(xen_host_record, other_config) },
+        { .key = "supported_bootloaders",
+          .type = &abstract_type_string_set,
+          .offset = offsetof(xen_host_record, supported_bootloaders) },
         { .key = "resident_VMs",
           .type = &abstract_type_ref_set,
           .offset = offsetof(xen_host_record, resident_vms) },
@@ -107,6 +110,7 @@ xen_host_record_free(xen_host_record *record)
     free(record->name_description);
     xen_string_string_map_free(record->software_version);
     xen_string_string_map_free(record->other_config);
+    xen_string_set_free(record->supported_bootloaders);
     xen_vm_record_opt_set_free(record->resident_vms);
     xen_string_string_map_free(record->logging);
     xen_pif_record_opt_set_free(record->pifs);
@@ -244,6 +248,23 @@ xen_host_get_other_config(xen_session *session, xen_string_string_map **result,
 }
 
 
+bool
+xen_host_get_supported_bootloaders(xen_session *session, struct xen_string_set **result, xen_host host)
+{
+    abstract_value param_values[] =
+        {
+            { .type = &abstract_type_string,
+              .u.string_val = host }
+        };
+
+    abstract_type result_type = abstract_type_string_set;
+
+    *result = NULL;
+    XEN_CALL_("host.get_supported_bootloaders");
+    return session->ok;
+}
+
+
 bool
 xen_host_get_resident_vms(xen_session *session, struct xen_vm_set **result, xen_host host)
 {
diff --git a/tools/libxen/src/xen_string_set.c b/tools/libxen/src/xen_string_set.c
new file mode 100644 (file)
index 0000000..8829433
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2006-2007, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ */
+
+
+#include "xen_internal.h"
+#include "xen_string_set.h"
+
+
+xen_string_set *
+xen_string_set_alloc(size_t size)
+{
+    xen_string_set *result = calloc(1, sizeof(xen_string_set) +
+                                    size * sizeof(char *));
+    result->size = size;
+    return result;
+}
+
+void
+xen_string_set_free(xen_string_set *set)
+{
+    if (set == NULL)
+    {
+        return;
+    }
+    size_t n = set->size;
+    for (size_t i = 0; i < n; i++)
+    {
+       free(set->contents[i]);
+    }
+
+    free(set);
+}
diff --git a/tools/libxen/src/xen_string_set.h b/tools/libxen/src/xen_string_set.h
new file mode 100644 (file)
index 0000000..a14af94
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2006-2007, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ */
+
+#ifndef XEN_STRING_SET_H
+#define XEN_STRING_SET_H
+
+
+#include "xen_common.h"
+
+
+typedef struct xen_string_set
+{
+    size_t size;
+    char *contents[];
+} xen_string_set;
+
+
+/**
+ * Allocate a xen_string_set of the given size.
+ */
+extern xen_string_set *
+xen_string_set_alloc(size_t size);
+
+/**
+ * Free the given xen_string_set.  The given set must have been allocated
+ * by this library.
+ */
+extern void
+xen_string_set_free(xen_string_set *set);
+
+
+#endif
index 90d33e4ff85f58acd352da0716082e1631bd52a5..c76768af157b8de970dfc91ee6091f59fadc2fcb 100644 (file)
@@ -222,6 +222,22 @@ int main(int argc, char **argv)
         return 1;
     }
 
+    xen_string_set *supported_bootloaders;
+    if (!xen_host_get_supported_bootloaders(session, &supported_bootloaders,
+                                            host))
+    {
+        print_error(session);
+        free(dmesg);
+        xen_string_string_map_free(versions);
+        xen_host_free(host);
+        xen_vm_record_free(vm_record);
+        xen_uuid_bytes_free(vm_uuid_bytes);
+        xen_uuid_free(vm_uuid);
+        xen_vm_free(vm);
+        CLEANUP;
+        return 1;
+    }
+
     printf("%s.\n", vm_uuid);
 
     fprintf(stderr, "In bytes, the VM UUID is ");
@@ -241,24 +257,39 @@ int main(int argc, char **argv)
 
     printf("Host dmesg follows:\n%s\n\n", dmesg);
 
+    printf("Host supports the following bootloaders:");
+    for (size_t i = 0; i < supported_bootloaders->size; i++)
+    {
+        printf(" %s", supported_bootloaders->contents[i]);
+    }
+    printf("\n");
+
     printf("%s.\n", vm_record->uuid);
 
     printf("Resident on %s.\n", (char *)vm_record->resident_on->u.handle);
 
     printf("%s.\n", xen_vm_power_state_to_string(vm_record->power_state));
 
-    print_vm_metrics(session, vm);
-
     xen_uuid_bytes_free(vm_uuid_bytes);
     xen_uuid_free(vm_uuid);
-    xen_vm_free(vm);
 
     xen_vm_record_free(vm_record);
 
     xen_host_free(host);
     xen_string_string_map_free(versions);
     free(dmesg);
+    xen_string_set_free(supported_bootloaders);
+
+    print_vm_metrics(session, vm);
+    if (!session->ok)
+    {
+        /* Error has been logged, just clean up. */
+        xen_vm_free(vm);
+        CLEANUP;
+        return 1;
+    }
 
+    xen_vm_free(vm);
 
     xen_vm new_vm = create_new_vm(session, true);
     if (!session->ok)